<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 230px;
      margin: 100px auto;
      position: relative;
      border-bottom: 1px solid #ccc;
      padding: 10px 0;
    }
    input {
      display: inline-block;
      border: 0;
      outline: none;
    }
    img {
      width: 30px;
      height: 30px;
      position: absolute;
      right: 0;
      top: 10px;
    }
  </style>
</head>
<body>
  <div class="box">
    <input type="text" />
    <img src="https://img2.baidu.com/it/u=1801400888,2357506857&fm=26&fmt=auto&gp=0.jpg" alt="">
  </div>

  <script>
    var input = document.querySelector('input')
    var img = document.querySelector('img')

    var flag = '脱了'  // 穿上

    img.onclick = function() {
      if(flag === '脱了') {
        img.src = 'https://img1.baidu.com/it/u=1869169834,2543923462&fm=26&fmt=auto&gp=0.jpg'
        input.type = 'password'
        flag = '穿上'
      } else {
        img.src = 'https://img2.baidu.com/it/u=1801400888,2357506857&fm=26&fmt=auto&gp=0.jpg'
        input.type = 'text'
        flag = '脱了'
      }
    }

    // var flag = true
    // img.onclick = function() {
    //   if(flag) {
    //     img.src = 'https://img1.baidu.com/it/u=1869169834,2543923462&fm=26&fmt=auto&gp=0.jpg'
    //     input.type = 'password'
    //     flag = false
    //   } else {
    //     img.src = 'https://img2.baidu.com/it/u=1801400888,2357506857&fm=26&fmt=auto&gp=0.jpg'
    //     input.type = 'text'
    //     flag = true
    //   }
    // }

    // 外翻  稳定支撑
  </script>
</body>
</html>